package homework10package;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 * Test class for homework 10
 * 
 * 
 * this class represents a single database for our index
 * 
 * 
 * @author Orion Taylor
 * @course Software Engineering
 * @date 4-2-13
 */

public class homework10Test {
	public static void main (String [] args)
			throws ClassNotFoundException, IOException{
		
		 
		Indexer my_Indexer=new Indexer();

		ArrayList  <urlreader> url_list =new ArrayList<urlreader>();
		
		Query asker= new Query();
		//url_list.add(new urlreader("http://www.serebii.net"));
		//url_list.add(new urlreader("http://www.google.com"));
		//url_list.add(new urlreader("http://en.wikipedia.org/wiki/PageRank"));
		//url_list.add(new urlreader("http://en.wikipedia.org/wiki/Eigenvector"));
		
		System.out.println("hello");
		
		my_Indexer.addurlreader(url_list);
		
		Index myIndex=my_Indexer.retrieveDatabase();
		
		//url_index maps url's to their integer codes
		HashMap<String,Integer> url_index=
				myIndex.getUrl_index();
		
		//term_index maps terms to their integer codes
		HashMap<String,Integer> term_index=
				myIndex.getTerm_index();
		
		//forward_edge_map maps urls to the url's they are linked to	
		HashMap<Integer,HashSet<Integer>> forward_edge_map=
				myIndex.getForward_edge_map();
		
		//backward_edge_maps maps urls to the url's that link to them
		HashMap<Integer,HashSet<Integer>> backward_edge_map=
				myIndex.getBackward_edge_map();
		
		//forward_term_map maps urls to the terms on their page
		//and their corresponding pair frequencies
		HashMap<Integer,HashMap<Integer,Integer>> forward_term_map=
				myIndex.getForward_term_map();
		
		//backward_term_map maps terms to the urls that have them
		//and their corresponding pair frequencies
		HashMap<Integer,HashMap<Integer,Integer>> backward_term_map=
				myIndex.getBackward_term_map();
		
		//urlRank maps url's to their respective page ranks
		HashMap<Integer, Double> urlRank = myIndex.getUrlRank();
		
		/*
		System.out.println(url_index);
		System.out.println(term_index);
		System.out.println(forward_edge_map);
		System.out.println(backward_edge_map);
		System.out.println(forward_term_map);
		System.out.println(backward_term_map);
		System.out.println(urlRank);
		*/
		
		for(Integer link: urlRank.keySet()){
			System.out.print(myIndex.getReverse_url_index().get(link));
			System.out.print("\t");
			System.out.println(urlRank.get(link));
		}
		
		System.out.println(asker.searchTerm("pagerank"));
		
		ArrayList<String> termlist=new ArrayList<String>();
		termlist.add("pagerank");
		termlist.add("eigenvector");
		System.out.println(asker.searchTerms(termlist));
		
		termlist.add("walasdf");
		System.out.println(asker.searchTerms(termlist));
	}
}
